package com.kyub.spring.gears.util;

import org.springframework.util.StringUtils;

import java.lang.reflect.InvocationTargetException;

/**
 * Utility class to gather introspection operations
 */
public class IntrospectionUtils {
    public static Object readPropertyValue(Object o, String s) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
        return o.getClass().getMethod("get" + StringUtils.capitalize(s), new Class[]{}).invoke(o, new Object[]{});
    }

    public static void writePropertyValue(Object o, String s, Object param) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
        o.getClass().getMethod("set" + StringUtils.capitalize(s), new Class[]{param.getClass()}).invoke(o, new Object[]{param});
    }
}
